﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Artemis;

namespace JAWWS
{
    class HandGun : Weapon
    {
        private double[] wPos = new double[3] { 0.0f, 0.0f, 0.0f };
        private float[] along = new float[3] { 0.0f, 0.0f, 0.0f };
        private float[] perp = new float[3] { 0.0f, 0.0f, 0.0f };
        private float along_scale = .15f;
        private float perp_scale = .5f;
        private const float DEG2RAD = (3.14159f / 180.0f);
        private float[] wAt;
        private float[] wEye;
        private float eyephi;
        private float eyetheta;

        public HandGun()
        {
            this.baseDammage = 10;
            this.ammoCount = 100;
            this.type = ItemName.HANDGUN;
        }
        public override ItemName getWeaponType()
        {
            return ItemName.HANDGUN;
        }

        public override int getBaseDammage()
        {
            return baseDammage;
        }

        public override int getAmmoCount()
        {
            return ammoCount;
        }
        public override int modifyAmmo(int amount)
        {
            return this.ammoCount += amount;
        }
        public override void apply(Player player)
        {
            //Does nothing for weapon
        }
        public override void draw()
        {
            //throw new NotImplementedException();
        }
        public override void drawWeapon(Camera camera)
        {
            wAt = camera.getAt();//get at[]
            wEye = camera.getCam();//get eye[]
            eyephi = camera.getTheta(1);//get eyePhi (elevation)
            eyetheta = camera.getTheta(0);//get eyetheta (azimuth)

            along[0] = (wAt[0] - wEye[0]);
            along[1] = (wAt[1] - wEye[1]);
            along[2] = (wAt[2] - wEye[2]);
            perp[0] = -(wAt[2] - wEye[2]);
            perp[1] = 0;
            perp[2] = (wAt[0] - wEye[0]);

            wPos[0] = wEye[0] + 1 * Math.Sin((eyetheta - 5) * DEG2RAD) * Math.Sin(eyephi * DEG2RAD);
            wPos[1] = wEye[1] + 1 * Math.Cos((eyephi - 10) * DEG2RAD);
            wPos[2] = wEye[2] + 1 * Math.Cos(eyetheta * DEG2RAD) * Math.Sin(eyephi * DEG2RAD);

            wPos[0] = wPos[0] + along_scale * along[0] + perp_scale * perp[0];
            wPos[1] = wPos[1] + along_scale * along[1] + perp_scale * perp[1];
            wPos[2] = wPos[2] + along_scale * along[2] + perp_scale * perp[2];

            wPos[1]--;

            GL.glPushMatrix();
                GL.glTranslatef((float)wPos[0], (float)wPos[1], (float)wPos[2]);
                GL.glRotatef((float)eyetheta, 0.0f, 1.0f, 0.0f);
                GL.glRotatef((float)eyephi, 1.0f, 0.0f, 0.0f);
                Toolkit.SolidCube(1.0);
            GL.glPopMatrix();
        }
    }
}
